<?php (!defined('IN_SYSTEM') || !defined('ADMIN_PRE')) && exit('Access Denied!');?>
{admintemplate header}
<div class="box">
	<div class="heading">
	<h1>分类管理</h1>
	<div class="buttons">
	<a href="{url admin.php?m=category&f=add&t=$t}" class="fr">添加分类</a>
	{loop $class $k $v}
	{if $v['table']}<a href="{url admin.php?m=category&t=$k}" {if $t==$k}class="current"{/if}>{$v['name']}</a>{/if}
	{/loop}
	</div>
	</div>

	<div class="main">

	<?php if ($f == 'index') {?>
		<form name="update" method="post" action="?m=category" autocomplete="off">
			<input type="hidden" name="f" id="f" value="" />
			<input type="hidden" name="t" id="t" value="{$t}" />
			<table class="list" cellspacing="0" id="list">
			<thead>
				<tr>
					<td width="1" class="firstcol"><input type="checkbox" name="chkall" id="chkall" class="checkbox" onclick="check_all(this)" /></td>
					<td class="center" >名称</td>
					<td class="center" width="70">统计</td>
					<td class="center" width="70">可见</td>
					<td class="center" width="70">排序</td>
					<td class="center" width="70">权限</td>
					<td class="center" width="130">操作</td>
				</tr>
				</thead>
				{php $groups = $_G['userobj']->user_group();}
				{loop $groups  $g}
				{php $group[$g['gid']]=$g['groupname'];}
				{/loop}
				{php $group[0]='所有';}
				<tbody>
				{loop $result $row}
				<tr id="row_{$row['cid']}">
					<td class="center"><input type="checkbox" name="id[]" value="{$row['cid']}" class="checkbox"></td>
					<td class="left"><span id="span{$row['cid']}"></span><a onclick="get_child({$row['cid']},this)" href="javascript:;">[+]</a> {$row['catename']}</td>
					<td class="center"><b style="color:red"><?php echo $row['total']?></b></td>
					<td class="center"><?php echo $row['status']?'否':'是' ?></td>
					<td class="center"><input type="text" name="order[<?php echo $row['cid']?>]" size="5" value="<?php echo $row['listorder']?>" /></td>
					<td class="center">{$group[$row['access']]}</td>
					<td class="center"><a href="?m=category&f=edit&id={$row['cid']}&t={$row['type']}">编辑</a> | <a href="?m=category&f=del&id=<?php echo $row['cid']?>" onclick="return delete_confirm();">删除</a> | <a href="?m=category&f=add&t={$t}&pid={$row['cid']}">添加下级</a></td>
				</tr>
				{/loop}
				<tr>
					<td align="center"><input type="checkbox" name="chkall" id="chkall" class="checkbox" onclick="check_all(this)" /></td>
					<td colspan="7" class="left">将选中分类合并到
					<select name="tocid">
						<option value="0">-- 请选择 --</option>
						<?php echo get_category_options(null,$t)?>
					</select>
					<input type="button" value="执行操作" class="button" onclick="do_submit('merge', this.form)" />
					<input type="button" value="更新排序" class="button" onclick="do_submit('save_order', this.form)" /> <input type="button" value="添加分类" onclick="window.location.href='?m=category&f=add&t=<?php echo $t?>'" class="button" />
					</td>
				</tr>
				</tbody>
			</table>
		</form>
		<script type="text/javascript">
		
		function get_child(id,obj){
			var group=new Array();group[0]="全部";
			{loop $groups  $g}
			group[{$g['gid']}]="{$g['groupname']}";
			{/loop}

				var html='';
				var span=$("#span"+id).html();
				var cla=$("#row_"+id).removeClass('tr_hover').attr("class");
				var t=$('#t').val();
			$.getJSON('admin.php?m=category&f=child&id='+id+'&tm='+Math.random(),'',function(data){
				if(data.s==true){
					for(var i=0;i<data.d.length;i++){
						var d=data.d[i];
							html+='<tr id="row_'+d.cid+'" class="cd'+id+' '+cla+'"><td class="center"><input type="checkbox" name="id[]" value="'+d.cid+'" class="checkbox"></td>';
							html+='<td class="left"><span id="span'+d.cid+'">'+span+'&nbsp;&nbsp;</span> <a onclick="get_child('+d.cid+', this)" href="javascript:;">[+]</a>'+d.catename+'</td>';
							html+='<td class="center"><b style="color:red">'+d.total+'</b></td>';
							html+='<td class="center">'+(d.status?'否':'是')+'</td>';
							html+='<td class="center"><input type="text" name="order['+d.cid+']" size="5" value="'+d.listorder+'" /></td>';
							html+='<td class="center">'+group[d.access]+'</td>';
							html+='<td class="center"><a href="?m=category&f=edit&id='+d.cid+'">编辑</a> | <a href="?m=category&f=del&id='+d.cid+'" onclick="return delete_confirm();">删除</a> | <a href="?m=category&f=add&t='+t+'&pid='+d.cid+'">添加下级</a></td>';
							html+='</tr>';
					}
					$(html).insertAfter($('#row_'+id));
					$(obj).html("[-]").removeAttr("onclick").one('click',function(){hide_child(id,this);});
				}else{
					$(obj).html("[-]").removeAttr("onclick");
				}
				});
		}
		function hide_child(id,obj){
			$(".cd"+id).hide();
			$(obj).html("[+]").one('click',function(){show_child(id,this);});
		}
		function show_child(id,obj){
			$(".cd"+id).show();
			$(obj).html("[-]").one('click',function(){hide_child(id,this);});
		}
		function delete_confirm(){
				return confirm('本操作将会删除该分类下的所有数据，建议你先做好数据备份，确定要删除吗？');
		}
		</script>



	<?php } elseif ($f == 'add' || $f == 'edit') { ?>

	<form name="save" method="post" action="?m=category&f=save" onsubmit="return category_save()" autocomplete="off">
	<input type="hidden" name="savetype" value="<?php echo $result['savetype']?>" />
	<input type="hidden" name="id" value="<?php echo $result['cid']?>" />
	{if $_G['gourl']}<input type="hidden" name="destination" value="{$_G['gourl']}" />{/if}
	<?php if($f == 'edit'){?>
	<input type="hidden" name="type" value="<?php echo $result['type']?>" />
	<?php }else{?>
	<input type="hidden" name="type" value="<?php echo $t?>" />
	<?php }?>
	<table>
		<tr>
			<td colspan="2"><div id="tip"></div></td>
		</tr>
		<tr>
			<td align="right" width="80">名称：</td>
			<td><input type="text" name="catename" id="title" class="input"   size="20" value="<?php echo $result['catename']?>" />
				&nbsp;上级:<select id="cparent" name="cparent">
				<option  value="0">根</option>
				
				<?php  foreach($cates as $cate):?>
				<option <?php if(isset($result['pid']) && $result['pid'] == $cate['cid']):?>selected="selected"<?php endif;?> {if $pid==$cate['cid']}selected{/if} value="<?php echo $cate['cid']?>"><?php echo $cate['catename']?></option>
				<?php endforeach;?>
				</select>
			</td>
		</tr>
		<tr>
			<td width="80" align="right">分类权限：</td>
			<td>
			<select name="access">
			{php $groups = $_G['userobj']->user_group();}
			<option value="0">全部</option>;
			{loop $groups $group}
			<option value="{$group['gid']}"  {if $group['gid']==$result['access']}selected{/if}>{$group['groupname']}</option>;
			{/loop}
			</select><span>设置哪些用户组的用户才可使用</span>
			</td>
		</tr>
		<tr>
			<td align="right">URL名称：</td>
			<td><input type="text" name="urlname" id="urlname" value="<?php echo $result['urlname']?>" class="input" size="50"  onblur="check_urlname()"/> <input type="checkbox" onclick="getalias(this)"/>自动获取    <span>启用URL Rewrite时可用。由字母、数字、下划线和减号组成，不能为单纯的数字。</span></td>
		</tr>
		<tr>
			<td align="right">关键字：</td>
			<td><input type="text" name="keywords" value="<?php echo $result['keywords']?>" class="input" size="50" /><span>设置页面meta标签的keywords，多个关键字用英文逗号","分隔</span></td>
		</tr>
		<tr>
			<td align="right">描述：</td>
			<td><textarea name="description" rows="5" cols="50"><?php echo $result['description']?></textarea><span>设置页面meta标签的description</span>
			</td>
		</tr>
		<tr>
			<td align="right">跳转：</td>
			<td><input type="text" name="redirect" value="<?php echo $result['redirect']?>" class="input" size="50" /><span>点击该分类要跳转到的地址</span></td>
		</tr>
		<tr>
			<td align="right">顺序：</td>
			<td><input type="text" name="listorder" value="{$result['listorder']}" class="input" size="50" /><span>值越大，显示越靠后</span></td>
		</tr>
		<tr>
			<td align="right">属性：</td>
			<td><input type="radio" name="status" value="0" class="radio" <?php echo $result['status']==0 ? 'checked="checked"' :''?> />公开 <input type="radio" name="status" value="1" class="radio" <?php echo $result['status']==1 ? 'checked="checked"' :''?> />隐藏 </td>
		</tr>
		<tr><td></td><td><input type="submit" class="button" value="保存分类" /> <input type="button" class="button" onclick="window.location.href='?m=category'" value="取消返回" /></td></tr>
	</table>
	</form>

	<?php }?>
	</div>
</div>
{admintemplate footer}